import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:mes_app/route/index.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarIconBrightness: Brightness.light,
      statusBarColor: Colors.transparent,
    ),
  );
  runApp(const MesApp());
}

class MesApp extends StatelessWidget {
  const MesApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MediaQuery.removePadding(
      context: context,
      removeBottom: true,
      removeLeft: true,
      removeRight: true,
      child: ScreenUtilInit(
        builder: (_, c) {
          return GetMaterialApp(
            title: 'MES制造',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              extensions: [TDThemeData.defaultData()],
              useMaterial3: true,
              brightness: Brightness.light,
            ),
            transitionDuration: const Duration(milliseconds: 500),
            defaultTransition: Transition.cupertino,
            enableLog: true,
            logWriterCallback: Logger.write,
            initialRoute: Routes.home,
            getPages: Routes.getPages,
            localizationsDelegates: [
              GlobalCupertinoLocalizations.delegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
            ],
          );
        },
      ),
    );
  }
}

mixin Logger {
  static void write(String text, {bool isError = false}) {
    Future.microtask(() => debugPrint('** $text. isError: [$isError]'));
  }
}
